<%@ page language="java" pageEncoding="UTF-8"
	errorPage="../../defaultException.jsp"%>
<%@include file="../../tags.jsp"%>
<html>
<head>
<title>目的地信息管理</title>
<meta HTTP-EQUIV="pragma" CONTENT="no-cache">
<meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<meta HTTP-EQUIV="expires" CONTENT="0">
<%@include file="../../head.jsp"%>


</head>
<body>

	<table class="fitem">
		<tr>
			<td><label>目的地名称:</label></td>
			<td><input id="destId" type="text" /></td>
			<td align="right"><button id="sub" value="查询"
					onclick="searchForm()">查询</button>
			</td>
		</tr>
	</table>

	<table id="list_data" cellspacing="0" cellpadding="0">
		<thead>
			<tr>
				<th field="operator" formatter="renderOperator">目的地管理</th>
				<th field="hotelEnable" formatter="renderHotelEnable">是否单独发布酒店</th>
				<th field="zhname">中文名</th>
				<th field="enname">英文名</th>
				<th field="countryName">归属国家名称</th>
				<th field="altitude">海拔高度</th>
				<th field="peopleNum">人口数量</th>
				<th field="lang">使用语言</th>
				<th field="destEnable" formatter="renderDestEnable">是否可用</th>
				<th field="style" formatter="renderDestStyle">展示风格</th>
				<th field="lng">目的地经度</th>
				<th field="lat">目的地纬度</th>
				<th field="tel">驻外大使馆电话</th>
				<th field="currency">使用货币</th>
				<th field="copyright">版权信息</th>
				<th field="summary">概述摘要</th>
			</tr>
		</thead>
	</table>
	<script type="text/javascript">
		var destEnableInfo = {
			'1' : '可用',
			'0' : '不可用'
		};

		function renderDestEnable(value, row, index) {
			return destEnableInfo[value];
		};
		var destStyle = {
				'1' : '分类展示',
				'2' : '不分类展示'
			};

		function renderDestStyle(value, row, index) {
				return destStyle[value];
			};
		var hotelEnable = {
			'0':'否',
			'1':'是'
		};
		function renderHotelEnable(value, row, index) {
			return hotelEnable[value];
		};
		//function formatCell(value, row, index) {
			//return "<img src='${image_domain}"+value+"' width='150' height='100'>";
		//}
		function renderOperator(value, row, index) {
			return "<a href='${cpath }/admin/dest/feature/vlist?destId="
					+ row.destId
					+ "'>特色</a>"
					+ "|"
					+ "<a href='${cpath }/admin/hotel/vlist?destId="
					+ row.destId
					+ "'>酒店</a>"
					+ "|"
					+ "<a href='${cpath }/admin/dest/traffic/level1/vlist?destId="
					+ row.destId
					+ "'>交通</a>";
		}
	</script>

	<div id="addDestinationDialog"
		style="width: 400px; height: 280px; padding: 10px 20px"></div>

	<script type="text/javascript">
		$('#list_data')
				.datagrid(
						{
							title : '目的地信息',
							iconCls : 'icon-edit',//图标 
							width : 1024,
							height : 500,
							doSize : true,
							nowrap : false,
							cache : false,
							striped : true,
							border : true,
							collapsible : false,//是否可折叠的 
							fitColumns : true,//自动大小 
							fit : false,
							url : '${cpath }/admin/dest/list',
							//sortName: 'code', 
							//sortOrder: 'desc', 
							remoteSort : false,
							idField : 'destId',
							singleSelect : true,//是否单选 
							pagination : true,//分页控件 
							rownumbers : true,//行号 
							//frozenColumns:[[ 
							//    {field:'ck',checkbox:true} 
							//]], 
							toolbar : [
									{
										text : '添加目的地',
										iconCls : 'icon-add',
										handler : function() {
											//openDialog("add_dialog","add");
											var saveAction = cpath
													+ '/admin/dest/save';
											var openAction = cpath
													+ '/admin/dest/vsave';
											openAddDestinationDialog('添加目的地信息',
													openAction, saveAction,
													addDestSuccess);
										}
									},
									'-',
									{
										text : '修改目的地',
										iconCls : 'icon-edit',
										handler : function() {
											//openDialog("add_dialog","add");
											var saveAction = cpath
													+ '/admin/dest/update';
											var openAction = cpath
													+ '/admin/dest/vupdate';
											openUpdateDestinationDialog(
													'修改目的地信息', openAction,
													saveAction, addDestSuccess,
													getSelectDest);
										}
									},
									'-',
									{
										text : '删除目的地',
										iconCls : 'icon-remove',
										handler : function() {
											//openDialog("add_dialog","add");
											var deleteAction = cpath
													+ '/admin/dest/delete';
											deleteDestInfo(deleteAction,
													getSelectDest);
										}
									}, '-', {
										text : '刷新',
										iconCls : 'icon-reload',
										handler : function() {
											$('#list_data').datagrid('reload');
											save_status = false;
										}
									} ]
						});
		//设置分页控件 
		var p = $('#list_data').datagrid('getPager');
		$(p).pagination({
			pageSize : 10,//每页显示的记录条数，默认为10 
			pageList : [ 5, 10, 15 ],//可以设置每页记录条数的列表 
			beforePageText : '第',//页数文本框前显示的汉字 
			afterPageText : '页    共 {pages} 页',
			displayMsg : '当前显示 {from} - {to} 条记录   共 {total} 条记录'
		/*onBeforeRefresh:function(){
		    $(this).pagination('loading');
		    alert('before refresh');
		    $(this).pagination('loaded');
		}*/
		});
	</script>
	<script type="text/javascript">
		var url;
		var cpath = '${cpath}';

		function getSelectDest() {
			return $('#list_data').datagrid('getSelected');
		}

		function addDestSuccess() {
			$('#list_data').datagrid('reload'); // reload the user data
		}

		function openAddDestinationDialog(dlgtitle, openAction, saveAction,
				successCallback) {
			$('#addDestinationDialog').dialog({
				title : dlgtitle,
				width : 800,
				height : 550,
				closed : false,
				cache : false,
				resizable : true,
				href : openAction,
				modal : true,
				closed : true,
				buttons : [ {
					text : '保存',
					iconCls : "icon-save",
					handler : function() {
						saveForm(saveAction, successCallback);
					}
				}, {
					text : '取消',
					iconCls : "icon-cancel",
					handler : function() {
						$('#addDestinationDialog').dialog('close');
					}
				} ]
			});

			$('#addDestinationDialog').dialog('open');
		}
		function openUpdateDestinationDialog(dlgtitle, openAction, saveAction,
				successCallback, selectRowHandler) {

			//添加信息，需要是否有前置条件
			if (selectRowHandler) {
				var row = selectRowHandler();
				//没有选中行，则需要提示
				if (!row) {
					$.messager.alert("提示", "请选择一个目的地", "info");
					return;
				} else {
					//选中了一行需在saveAction后加上目的地编号
					openAction += '?destId=' + row.destId;
				}
			}
			$('#addDestinationDialog').dialog({
				title : dlgtitle,
				width : 800,
				height : 550,
				closed : false,
				cache : false,
				resizable : true,
				href : openAction,
				modal : true,
				closed : true,
				buttons : [ {
					text : '保存',
					iconCls : "icon-save",
					handler : function() {
						saveForm(saveAction, successCallback);
					}
				}, {
					text : '取消',
					iconCls : "icon-cancel",
					handler : function() {
						$('#addDestinationDialog').dialog('close');
					}
				} ]
			});

			$('#addDestinationDialog').dialog('open');
			$('#list_data').datagrid('clearSelections');
		}
		var save_status = false;
		function saveForm(saveAction, successCallback) {
			if (save_status) {
				$.messager.alert("提示", "请耐心等待。。。后台执行中。。。", "info");
				return;
			}
			save_status = true;
			$('#fm').form('submit', {
				url : saveAction,
				onSubmit : function() {
					var result = $(this).form('validate');
					if (!result) {
						save_status = false;
					}
					return result;
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.resultCode !== '00000000') {
						$.messager.alert("错误", result.resultMsg, "error");
						$('#list_data').datagrid('clearSelections');
					} else {
						$.messager.alert("成功", result.resultMsg, "info");
						$('#addDestinationDialog').dialog('close');
						if (successCallback) {
							successCallback();
						}
						$('#list_data').datagrid('clearSelections');
					}
					save_status = false;
				}
			});
		}
		function searchForm() {
			var destName = $('#destId').attr("value");

			$('#list_data').datagrid('load', {
				destName : destName
			});
		}

		function deleteDestInfo(deleteAction, getSelectDest) {
			//添加信息，需要是否有前置条件
			if (getSelectDest) {

				var row = getSelectDest();
				//没有选中行，则需要提示
				if (!row) {
					$.messager.alert("提示", "请选择要删除的目的地！", "info");
					return;
				}
				if (row) {
					$.messager.confirm("提示", "确认要删除目的地吗？", function(r) {
						if (r) {
							$.post(deleteAction, row,
									function(result) {
										if (result.resultCode === '00000000') {
											$('#list_data').datagrid('reload'); // reload the user data
											$.messager.alert("提示",
													result.resultMsg, "info");
											$('#list_data').datagrid(
													'clearSelections');
										} else {
											$.messager.alert("错误",
													result.resultMsg, "error");
											$('#list_data').datagrid(
													'clearSelections');
										}
									}, 'json');
						}
					});
				}
			}
		}
	</script>

</body>
</html>